function ListNode(val, next) {
      this.val = (val===undefined ? 0 : val)
      this.next = (next===undefined ? null : next)
 }




var mergeTwoLists = function(list1, list2) {
let head=new listNode()//{val:0,next=null}
let cur=head
while(list1&&list2){
    if(list1.val<=list2.val)
    {
        cur.next=list1
        list1=list1.next
    }
    else{
        cur.next=list2
        list2=list2.next
    }
    cur = cur.next;
}
    if(list1){
        cur.next=list1
    }
    else{
        cur.next=list2
    }

        return head.next

};
console.log(mergeTwoLists())